const Koa = require('koa')
const koaBody = require('koa-body');
const Auth = require('./middlewares/auth');
const {
    logger
} = require('./config/logs');
const app = new Koa()



//处理异常中间件
const catchError = require('./middlewares/exception')
app.use(catchError)

app.use(koaBody());

app.use(new Auth().m)

//初始化文件
const initManager = require('./core/init');

initManager.initCore(app)

const swagger = require('./utils/swagger')
app.use(swagger.routes(), swagger.allowedMethods())
const {koaSwagger} = require('koa2-swagger-ui');
const redis = require('./core/redis');
// redis.set('list',[{
//     a:1,
//     b:2
// }])

redis.get('list').then(function (result) {
    console.log(result);
  });
  
// //测试多个定时任务
// const { order,order1 } = require('./schedule/order');
// var a = new order('* * * * * * ')
// var b = new order1('* * * * * * ')
// setTimeout(()=>{
//     //关闭定时器
//     a.cancel()
// },5000)

// setTimeout(()=>{
//     //关闭定时器
//     b.cancel()
// },8000)



app.use(koaSwagger({
    routePrefix: '/swagger', // host at /swagger instead of default /docs
    swaggerOptions: {
        url: '/swagger.json', // example path to json 其实就是之后swagger-jsdoc生成的文档地址
    },
}))
app.listen(3000, '0.0.0.0')
app.on('error', err => {
    logger.error(err);
});